package cn.com.cetccst.datacenter.message;

import android.content.Context;

import androidx.lifecycle.LiveData;
import androidx.room.Room;

import java.util.List;

import cn.com.cetccst.datacenter.message.dao.InboxMessageDao;
import cn.com.cetccst.datacenter.message.entity.InboxMessageEntity;

public class InboxMessageRespository {

    private static final String DB_NAME = "ss_inbox_message.db";
    private static InboxMessageRespository INSTANCE;

    private InboxMessageDao inboxMessageDao;

    public InboxMessageRespository(Context context) {
        InboxMessageDataBase dataBase = Room.databaseBuilder(context, InboxMessageDataBase.class, DB_NAME)
                .allowMainThreadQueries()
                .build();

        inboxMessageDao = dataBase.getInboxMessageDao();
    }

    public static InboxMessageRespository getInstance() {
        return INSTANCE;
    }

    public static void initialize(Context context) {
        INSTANCE = new InboxMessageRespository(context);
    }

    public LiveData<List<InboxMessageEntity>> getAllMessage() {
        return inboxMessageDao.getAll();
    }

    public void saveMessage(InboxMessageEntity entity) {
        inboxMessageDao.insert(entity);
    }

    public LiveData<Integer> getUnreadCount() {
        return inboxMessageDao.unreadCount();
    }

    public void readAll() {
        inboxMessageDao.readAll();
    }
}
